//
//  TaskSortTableViewCell.m
//  OAProject
//
//  Created by yhj on 2017/3/16.
//  Copyright © 2017年 cdnunion. All rights reserved.
//

#import "TaskSortTableViewCell.h"

@interface TaskSortTableViewCell ()

@property(nonatomic,strong)UIView *lineView;

// 创建分类的时间
@property(nonatomic,strong)UILabel *taskSortTimeLabel;

// 分类名字
@property(nonatomic,strong)UILabel *taskSortNameLabel;

// 编辑
@property(nonatomic,strong)UIButton *editBtn;

// 删除
@property(nonatomic,strong)UIButton *deleteBtn;

@end

@implementation TaskSortTableViewCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self=[super initWithStyle:style reuseIdentifier:reuseIdentifier])
    {
        // ➡️Cell类型
        self.accessoryType=UITableViewCellAccessoryNone;

        self.lineView.hidden=NO;

        self.taskSortTimeLabel.font=Font_Number(14);

        self.taskSortNameLabel.font=Font_Number(16);

        self.editBtn.hidden=NO;

        self.deleteBtn.hidden=NO;

        self.backgroundColor=WhiteColor;

    }
    return self;
}

-(UIView *)lineView
{
    if (!_lineView) {
        _lineView=[UIView new];
        _lineView.backgroundColor=BGColor;
        [self.contentView addSubview:_lineView];
        [_lineView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(APPW,kmargin));
            make.top.mas_equalTo(0);
        }];
    }
    return _lineView;
}


// taskSortTimeLabel
- (UILabel *)taskSortTimeLabel
{
    if (!_taskSortTimeLabel) {
        _taskSortTimeLabel=[self getLabelWithText:@"2017年3月4日创建" font:Font_Number(14) textColor:LightGreyColor textAlignment:NSTextAlignmentLeft lineBreakMode:NSLineBreakByCharWrapping numberOfLines:1];
        [self.contentView addSubview:_taskSortTimeLabel];
        [_taskSortTimeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self.lineView.mas_bottom).offset(kmargin*3/2);
            make.left.mas_equalTo(kmargin*2);
        }];
    }
    return _taskSortTimeLabel;
}

// taskSortNameLabel
- (UILabel *)taskSortNameLabel
{
    if (!_taskSortNameLabel) {
        _taskSortNameLabel=[self getLabelWithText:@"质量" font:Font_Number(16) textColor:DarkGreyColor textAlignment:NSTextAlignmentLeft lineBreakMode:NSLineBreakByTruncatingTail numberOfLines:1];
        [self.contentView addSubview:_taskSortNameLabel];
        [_taskSortNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self.taskSortTimeLabel.mas_bottom).offset(kmargin);
            make.left.mas_equalTo(self.taskSortTimeLabel.mas_left);
            make.right.mas_equalTo(self.editBtn.mas_left).offset(-kmargin);
        }];
    }
    return _taskSortNameLabel;
}

// editBtn
-(UIButton *)editBtn
{
    if (!_editBtn) {
        _editBtn=[AppUI createButtonWithSupeView:self.contentView andWithNormalImage:[UIImage imageNamed:@"EditIcon"] andWithSelectImage:[UIImage imageNamed:@"EditIcon"] andWithBtnAction:^{

          if (self.delegate&&[self.delegate respondsToSelector:@selector(editTaskSortWithSortModel:cell:)]) {
                 [self.delegate editTaskSortWithSortModel:self.sortModel cell:self];
            }

        }];
        [self.contentView addSubview:_editBtn];
        [self.editBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.mas_equalTo(self.taskSortNameLabel.mas_centerY);
            make.right.mas_equalTo(self.deleteBtn.mas_left).offset(-kmargin*2);
            make.size.mas_equalTo(CGSizeMake(kmargin*2.5,kmargin*2.5));

        }];
    }
    return _editBtn;
}

// deleteBtn
-(UIButton *)deleteBtn
{
    if (!_deleteBtn) {
        _deleteBtn= _editBtn=[AppUI createButtonWithSupeView:self.contentView andWithNormalImage:[UIImage imageNamed:@"DeleteIcon"] andWithSelectImage:[UIImage imageNamed:@"DeleteIcon"] andWithBtnAction:^{

            if (self.delegate&&[_delegate respondsToSelector:@selector(deleteTaskSortWithSortModel:cell:)]) {
                [self.delegate deleteTaskSortWithSortModel:self.sortModel cell:self];
            }
        }];
        [self.contentView addSubview:_deleteBtn];
        [self.deleteBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.mas_equalTo(-kmargin*2);
            make.left.mas_equalTo(self.editBtn.mas_right).offset(kmargin*2);
            make.size.mas_equalTo(CGSizeMake(kmargin*2.5,kmargin*2.5));
            make.centerY.mas_equalTo(self.taskSortNameLabel.mas_centerY);
        }];
    }
    return _deleteBtn;
}

-(void)setSortModel:(SortModel *)sortModel
{
    _sortModel=sortModel;
    self.taskSortNameLabel.text=sortModel.target_name;
    self.taskSortTimeLabel.text=[NSString stringWithFormat:@"%@ 创建",sortModel.in_time];
}

@end
